﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.EdgeBytes
{
    public class BytesHelper
    {

        public static byte[] intToBytes(int value)
        {
            byte[] src = new byte[4];
            src[0] = (byte)((value >> 24) & 0xFF);
            src[1] = (byte)((value >> 16) & 0xFF);
            src[2] = (byte)((value >> 8) & 0xFF);
            src[3] = (byte)(value & 0xFF);
            return src;
        }


        /// <summary>
        /// 字符串转 byte[]
        /// 00-00-00-00-00-06-78-03-00-67-00-02 => new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x78, 0x03, 0x00, 0x67, 0x00, 0x02 };
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public static byte[] EdgeGetBytes(string result)
        {
            string[] strSplit = result.Split('-');
            byte[] bytTemp2 = new byte[strSplit.Length];
            for (int i = 0; i < strSplit.Length; i++)
                bytTemp2[i] = byte.Parse(strSplit[i], System.Globalization.NumberStyles.AllowHexSpecifier);


            //string stringdata = BitConverter.ToString(bytTemp2, 0, bytTemp2.Length);
            return bytTemp2;



        }

    }
}
